import { ReactNode } from "react";
import Icon from "../Icon";
import styles from './index.module.scss'
import { useHistory } from 'react-router'
import classNames from 'classnames'
type prpos = {
  onBack?: () => void;
  title?: ReactNode;
  children?: ReactNode;
  right?: ReactNode;
  fixed?: boolean
}
export default function navBar({ onBack, title, right, children, fixed }: prpos) {

  // eslint-disable-next-line react-hooks/rules-of-hooks
  const history = useHistory()
  const back = () => {
    onBack ? onBack() : history.go(-1)
  }
  return (
    <div className={styles.root}>
      <div className={classNames('main', fixed ? 'fixed' : '')}>
        {/* 后退按钮 */}
        <div className="left" onClick={back}>
          <Icon type="iconfanhui" />
        </div>
        {/* 居中标题 */}
        <div className="title">{children || title}</div>
        {/* 右侧内容 */}
        <div className="right">{right}</div>
      </div>
    </div>
  )
}
